<?php
declare (strict_types=1);

namespace app\admin\controller;

use think\App;
use think\facade\View;
use think\response\Json;

class LntegralCate extends Base
{

    protected string $pk = 'id';

    protected string $model = '\app\common\model\LntegralCate';
    protected string $Productmodel = '\app\common\model\Lntegral';

    protected int $writeLog = 2;


    public function index(): string
    {
        View::assign('list', $this->model::getAll());
        return View::fetch();
    }

    public function edit($id = '', $pid = '', $tpl = 'lntegral_cate/edit'): string
    {
        return parent::edit($id, $tpl);
    }
    public function getCate(): \think\response\Json
    {
        return json($this->model::getCate());
    }

    public function updateStatus($key, $val, $id): Json
    {
        try {
            if ($val == 'true') $val = 1;
            if ($val == 'false') $val = 0;
            $this->model::update([$key => $val], ['id' => $id]);
            $this->Productmodel::update([$key => $val], ['cate_1' => $id]);
            return json(['code' => 1, 'msg' => '操作成功']);

        } catch (\Exception $e) {
            return json(['code' => -1, 'msg' => $e->getMessage()]);
        }

    }

}
